import { useTextStore } from "@/stores/config/configTextStore";
import { ConfigDataType } from "./enum";
import type { ConfigTableHeader } from "./struct";
import { useConfigTableStore } from "@/stores/config/configTableStore";

export class ViewHelper{
    static getElementTextByType(type: ConfigDataType, quoteId: number, value: number, defaultString: string = "") {
        let tableStore = useConfigTableStore()
        let textStore = useTextStore()
        switch(type) {
            case ConfigDataType.Integer:
                return value.toString()
            case ConfigDataType.Float:
                return value.toString()
            case ConfigDataType.String:
                return textStore.getTextById(value)
            case ConfigDataType.Boolean:
                return value ? "true" : "false"
            case ConfigDataType.Quote:
                if (!tableStore.hasTable(quoteId)) {
                    return "配表丢失, id:" + quoteId;
                } else if (!tableStore.hasTableRow(quoteId, value)) {
                    let tbl = tableStore.getTable(quoteId)
                    return "配表行丢失：" + tbl!.name + " id:" + value
                } else {
                    let str = ""
                    let tbl = tableStore.getTable(quoteId)
                    let row = tableStore.getTableRow(quoteId, value)
                    for (let i = 0; i < tbl!.tableHeader.length; i++) {
                        let subHeader = tbl!.tableHeader[i]
                        if (i != 0) {
                            str += " "
                        }
                        str += this.getTableElementText(subHeader, row!.values[i])
                    }
                    return str
                }
            default:
                return defaultString // 其他类型由原方法处理
        }
    }

    static getTableElementText(header: ConfigTableHeader, value: number) {
            return this.getElementTextByType(header.type, header.quoteId, value)
    }
    static getString(id: number) {
        let textStore = useTextStore()
        return textStore.getTextById(id)
    }
}